package com.binance.healthcenter.config;

import java.util.List;
import java.util.Set;

import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "com.binance.notification.sms")
public class SmsNotificationConfig {
    private List<ServiceConfiguration> services;
    private String tplcode;
    private String userid;
    private String defaultcellphones;

    public String getDefaultcellphones() {
        return defaultcellphones;
    }

    public void setDefaultcellphones(String defaultcellphones) {
        this.defaultcellphones = defaultcellphones;
    }

    public String getTplcode() {
        return tplcode;
    }

    public void setTplcode(String tplcode) {
        this.tplcode = tplcode;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public List<ServiceConfiguration> getServices() {
        return services;
    }

    public void setServices(List<ServiceConfiguration> services) {
        this.services = services;
    }

    public Set<String> getDefaultCellphoneSet() {
        String cellphones = getDefaultcellphones();
        if (StringUtils.isBlank(cellphones)) {
            return Sets.newHashSet();
        }
        Set<String> cellPhoneSet = Sets.newHashSet();
        String[] cellphoneArray = cellphones.split(",");
        for (String cellphone : cellphoneArray) {
            cellPhoneSet.add(cellphone);
        }
        return cellPhoneSet;
    }

    public static class ServiceConfiguration {
        private String application;
        private String cellphones;

        public String getApplication() {
            return application;
        }

        public void setApplication(String application) {
            this.application = application;
        }

        public String getCellphones() {
            return cellphones;
        }

        public void setCellphones(String cellphones) {
            this.cellphones = cellphones;
        }

        public Set<String> getCellphoneSet() {
            return spliteCellPhoneSet(getCellphones());
        }

        private Set<String> spliteCellPhoneSet(String cellphones) {
            if (StringUtils.isBlank(cellphones)) {
                return Sets.newHashSet();
            }
            Set<String> cellPhoneSet = Sets.newHashSet();
            String[] cellphoneArray = cellphones.split(",");
            for (String cellphone : cellphoneArray) {
                cellPhoneSet.add(cellphone);
            }
            return cellPhoneSet;
        }
    }
}


